package org.novaacropole.util;

import java.io.Serializable;

import javax.mail.Address;
import javax.mail.Message;
import javax.mail.internet.InternetAddress;
import javax.mail.search.SearchTerm;

public class GmailBounceSearch extends SearchTerm implements Serializable {

	private static final long serialVersionUID = 1L;

	@Override public boolean match(Message message) {
		try {
			for (Address address : message.getFrom()) {
				String daemon = ((InternetAddress) address).getAddress();
				if (daemon.equals("mailer-daemon@googlemail.com"))
					return true;
			}
			return false;
		} catch (Exception e) {
			throw new RuntimeException(e);
		}
	}

}
